package ${package.Controller};

import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpSession;

<#if restControllerStyle>
<#else>
    import org.springframework.stereotype.Controller;
</#if>


import java.util.List;
import javax.servlet.http.HttpSession;
/**
*
* @author ${author}
* @since ${date}
*/

<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
public class ${table.controllerName} {
    @Autowired
    HttpSession httpSession;

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    @RequestMapping("/jsp/${entity?uncap_first}List.do")
    public String ${entity?uncap_first}List(String pageIndex) {
        int  currentPageNo = pageIndex==null?1:Integer.valueOf(pageIndex);
        Page page = Page.of(currentPageNo,5);
        ${entity} ${entity?uncap_first} = new ${entity}();

        IPage<${entity}> ${entity?uncap_first}IPage =  ${table.serviceName?uncap_first}.get${entity}ByPage(page,${entity?uncap_first});
        httpSession.setAttribute("${entity?uncap_first}List",${entity?uncap_first}IPage.getRecords());
        httpSession.setAttribute("totalPageCount",${entity?uncap_first}IPage.getPages());
        httpSession.setAttribute("totalCount",${entity?uncap_first}IPage.getTotal());
        httpSession.setAttribute("currentPageNo",currentPageNo);
        return "providerlist";
    }

    @RequestMapping("/jsp/add${entity}.do")
    public String add${entity}(${entity} ${entity?uncap_first}){
        ${table.serviceName?uncap_first}.add${entity}(${entity?uncap_first});
        return   "redirect:/jsp/${entity?uncap_first}List.do";
    }

    @RequestMapping("jsp/upd${entity}.do")
    public String upd${entity}(${entity} ${entity?uncap_first}){
             ${table.serviceName?uncap_first}.upd${entity}(${entity?uncap_first});
             return   "redirect:/jsp/${entity?uncap_first}List.do";
    }


    @RequestMapping("/jsp/del${entity}.do")
    @ResponseBody
    public HashMap del${entity}(String id) {
        ${table.serviceName?uncap_first}.del${entity}(id);
        HashMap resultMap = new HashMap<>();
        resultMap.put("delResult", "true");
        return resultMap;
    }


    @RequestMapping("/jsp/view${entity}.do")
    public String view${entity}(String method,String id){

        ${entity} ${entity?uncap_first} =   ${table.serviceName?uncap_first}.get${entity}ById(id);
        httpSession.setAttribute("${entity?uncap_first}",${entity?uncap_first});
        if(method.equals("view")){
            return   "${entity}view";
        }else {
            return   "${entity}modify";
        }
    }


}